//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    abstract class RangeTokenBase: EmptyFormulaToken
    {
        internal override sealed Expression GetExpression(FormulaEvaluationContext context)
        {
            FormulaToken t1 = context.PoppedArgument();
            Expression right = t1.GetExpression(context);
            FormulaToken t2 = context.PoppedArgument();
            Expression left = t2.GetExpression(context);
            if (left is ErrorExpression)
                return left;
            if (right is ErrorExpression)
                return right;
            return CreateExpression((CellEnumeratorExpression) left, (CellEnumeratorExpression) right);
        }

        protected abstract Expression CreateExpression(CellEnumeratorExpression left, CellEnumeratorExpression right);
    }
}